<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .grey {
            background-color: grey;
        }
    </style>
</head>

<body>
    <div id="box">
        <input type="text">
        <br>
        <input type="text">
        <br>
        <input type="text">
        <br>
        <input type="text">
        <br>
        <input type="text">
    </div>
    <script>
        var box = document.getElementById("box");
        var inputs = box.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            inputs[i].onfocus = function () {
                // 排他思想，所有文本框背景恢复默认
                for (var j = 0; j < inputs.length; j++) {
                    inputs[j].className = "";
                }
                // 自身文本框背景设为灰色
                this.className = "grey";
            };
        }
    </script>
</body>

</html>